package fonctions;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.res.AssetManager;
import au.com.bytecode.opencsv.CSVReader;

public class CSVRead {
	String path;
	Context context;
	
	public CSVRead(Context context, String path){
		this.path = path;
		this.context = context;
		readCsv();
	}
	
	private final List<String[]> readCsv() {
		  List<String[]> questionList = new ArrayList<String[]>();
		  AssetManager assetManager = context.getAssets();

		  try {
		    InputStream csvStream = assetManager.open(path);
		    InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
		    CSVReader csvReader = new CSVReader(csvStreamReader);
		    String[] line;

		    // throw away the header
		    csvReader.readNext();

		    while ((line = csvReader.readNext()) != null) {
		      questionList.add(line);
		    }
		  } catch (IOException e) {
		    e.printStackTrace();
		  }
		  return questionList;
		}

}
